﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace T6
{
    class Program
    {
        //func：收入一个Student，{经过一系列判断（这个学生符合我们的查询要求吗）}，最终返回bool
        public static List<Student> Query(List<Student> list, Func<Student,bool> func)
        {
            List<Student> ll = new List<Student>();

            foreach (Student s in list)
            {
                if (func(s))
                {
                    ll.Add(s);
                }
            }

            return ll;
        }

        static void Main(string[] args)
        {
            List<Student> list = new List<Student>();
            list.Add(new Student
            {
                Name = "张三",
                Gender = '男',
                Birthday = new DateTime(1989,10,1)
            });
            list.Add(new Student
            {
                Name = "李四",
                Gender = '男',
                Birthday = new DateTime(1999, 10, 1)
            });
            list.Add(new Student
            {
                Name = "董悦",
                Gender = '女',
                Birthday = new DateTime(1996, 10, 1)
            });
            list.Add(new Student
            {
                Name = "董冰",
                Gender = '女',
                Birthday = new DateTime(2000, 9, 1)
            });

            //List<Student> ll = Query(list, (s) => {
            //    return s.Gender == '男';
            //});
            //foreach (Student s in ll)
            //{
            //    Console.WriteLine($"姓名：{s.Name}\t性别：{s.Gender}\t出生日期：{s.Birthday}");
            //}
            //Console.WriteLine("-----------------");

            //ll = Query(list, (s) => {
            //    return s.Gender == '男' && s.Name[0]=='张';
            //});
            //foreach (Student s in ll)
            //{
            //    Console.WriteLine($"姓名：{s.Name}\t性别：{s.Gender}\t出生日期：{s.Birthday}");
            //}

            var ll = list.FindAll((s) =>
            {
                return s.Gender == '女';
            });
            foreach (Student s in ll)
            {
                Console.WriteLine($"姓名：{s.Name}\t性别：{s.Gender}\t出生日期：{s.Birthday}");
            }
        }
    }
}
